<?php
  /*****************************************************
   * Rapidleech 36B Rv.8
   *
   * $Id: init.php - 05apr2010-Idx $
  *****************************************************/

if (!defined('RAPIDLEECH')){
  require_once("../404.php");exit;
}


error_reporting(E_ALL & ~E_NOTICE);
//error_reporting(E_ALL);
//error_reporting(0);
@ini_set('display_errors', true); 

@set_time_limit(0);
ini_alter("memory_limit", "1024M");
@ob_end_clean();
if(isset($_POST['link'])){
  @ob_implicit_flush(TRUE);
}
ignore_user_abort(1);
clearstatcache();
error_reporting(6135);

$nn = "\r\n";
$fromaddr = "RapidLeech";
$dev_name = ' - Release.Candidate';
$rev_num = '36B.Rv8.0';
$RL_VER = 'Rx08.ii'.$rev_num;

if(!defined("THIS_SCRIPT")) define('THIS_SCRIPT', 'index.php');

$PHP_SELF = !isset($PHP_SELF) ? $_SERVER["PHP_SELF"] : $PHP_SELF;
define('PATH_SPLITTER', (strstr(realpath("./"), "\\")!==false ? "\\" : "/"));
define('ROOT_DIR', realpath("./") . PATH_SPLITTER );
define('HOST_DIR', 'hosts/');
define('STATIC_DIR', 'static/');
define('CLASS_DIR', 'classes/');
define('CONFIG_DIR', 'configs/');
define('LANG_DIR', CLASS_DIR.'languages/');
//define("TIME_NOW", time());

$loca["thisFile"] = str_replace('\\', '/', __FILE__);
$loca["docRoot"] = $_SERVER['DOCUMENT_ROOT'] . (substr($_SERVER['DOCUMENT_ROOT'],-1) != "/" ? "/":"");
$webRoot = str_replace(array($loca["docRoot"], CLASS_DIR.basename(__FILE__) ), '', $loca["thisFile"]);
unset($loca);
if($webRoot=="/") $webRoot = "";
define('ROOT_URL', "http://". $_SERVER["SERVER_NAME"] . "/" . $webRoot);

// Load function and class
require_once(CLASS_DIR."other.php");

// Load configuration & accounts
require(CONFIG_DIR."config.php");
require(CONFIG_DIR."accounts.php");

// Set server timezone; TIME_NOW will set here
$tzone = getNowzone();
define("TIME_NOW", $tzone);

require_once(CLASS_DIR."timers.class.php");
$maintimer = new timer();
$maintimer->timer();

// $download_dir should always end with '/'
if (substr($options["download_dir"],-1) != '/') $options["download_dir"] .= '/';
define('DOWNLOAD_DIR', (substr($options["download_dir"], 0, 6) == "ftp://" ? '' : $options["download_dir"]));

define('TEMPLATE_DIR', 'tpl/'.$options['template_used'].'/');
define('IMAGE_DIR', TEMPLATE_DIR . 'skin/'. $options["csstype"] . '/');

// Language initialisation
require_once(CLASS_DIR."lang.class.php");
$L = new RxLang;
$L->set_path(LANG_DIR);

// Check language
if(!$options['lang'] || ($options['lang'] && !$L->language_exists($options['lang']))){
   $options['lang'] = 'english';
}
// Load language
$L->set_language($options['lang']);
$L->load("global");
$charSet = $L->settings["charset"];
//==== language global loaded here


// Check DOWNLOAD_DIR and FILES_LST
$czFlst = checkExistence();

// Strict check firbidden file in DOWNLOAD_DIR
checkStrict();

$deleted = ($options["auto_del_time"] > 0 ? purge_files($options["auto_del_time"]):0);

// check for forbidden page (audl, auul, lynx)
$keyfn = str_replace(".".get_extension(THIS_SCRIPT), "", THIS_SCRIPT);
if(isset($options["forbid"]["_{$keyfn}"]) && $options["forbid"]["_{$keyfn}"]){
   get_tpl("deadpage", ucwords(do_strtolower($keyfn)). " ".$L->say["disabled"]);  
   exit();
}

// Load server spec
$server = getServerPlatf();
// get real IP
$ipmu = get_real_ip();

// list main page with UI
$mainpage = array($options['index_file'], 'audl.php', 'auul.php', 'lynx.php', 'del.php' );


// based on opened main-page
if(in_array(THIS_SCRIPT, $mainpage)){
  switch(THIS_SCRIPT) {
   case "index.php":
        if ($options["no_cache"]) {
          header("Expires: Mon, 26 Jul 2010 05:00:00 GMT");
          header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
          header("Cache-Control: no-cache, must-revalidate");
          header("Pragma: no-cache");
        }
        
        if(!defined('CRLF')) define('CRLF',"\r\n");
        if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1);
        if(!defined("FTP_BINARY")) define("FTP_BINARY", 1);
        if(!defined("FTP_ASCII")) define("FTP_ASCII", 0);
        if(!defined('FTP_FORCE')) define('FTP_FORCE', TRUE);
        define('FTP_OS_Unix','u');
        define('FTP_OS_Windows','w');
        define('FTP_OS_Mac','m');
	    
	    $L->load("index");
	    
	    // Init call create_list
        if( $czFlst==0 && (!isset($_COOKIE["showAll"]) || (isset($_COOKIE["showAll"]) && $_COOKIE["showAll"]!=1) )){
          _create_list(false, true); // medic mode, to force list in downloaded files
          updateListInFile($list);
	      //updateCozEmpty(FILES_LST); // relist file    
        }
	    
	    if(!isset($list)) _create_list();
	    
	    register_shutdown_function("pause_download");
	
   break;
   
   case "audl.php":
        $L->load("audl");
   break;
   
   case "auul.php":
        if(!defined('UPLOAD_DIR')) define('UPLOAD_DIR', HOST_DIR . 'upload/');
        require_once(HOST_DIR."download/hosts.php");
        require_once(CLASS_DIR."http.php");
   break;
   
   case "lynx.php": case "del.php":
        $L->load("lynxdel");
        // no  break here
        case "lynx.php":
     	   $server = getServerPlatf( 1 );
   break;
  } // end switch
  
  
  if(THIS_SCRIPT=="index.php" || THIS_SCRIPT=="audl.php"){
     require_once(CLASS_DIR."limitation.php");
  }  
  //Cek ip yg banned || is it listed as authorized ip || check country limit
  if($options["limited_edition"] || $options["limited_area"]){
    $dlimitation = array($options["limited_edition"], $options["limited_area"]);
    require_once(CLASS_DIR."limit_district.php");
  }

}  // end based on main-page


login_check();

if($options["downloadLimitbyip"]) purge_files_ip($options["downloadDelayPerIP"]);

if($options["OnlineVisitor"] || $options["logact"]) {
  require_once(CLASS_DIR."visitors.class.php");
  $visitors = new Visitor;
}
if($options["OnlineVisitor"]) $visitors->updOnlineUser();

if($options["logact"]){
  if(!$visitors->is_latestVisitor()) $visitors->updLogVisitor('IN'); 
}

?>